package sjtu.ist.warehouse4ws.dao;

import java.util.List;

import sjtu.ist.warehouse4ws.model.Company;
import sjtu.ist.warehouse4ws.model.User;

public class CompanyDaoHibernate extends BaseDaoHibernate implements CompanyDao{

	@Override
	public Company get(String id) {
		return (Company)getHibernateTemplate().get(Company.class, id);
	}

	@Override
	public String save(Company company) {
		return (String)getHibernateTemplate().save(company);
	}

	@Override
	public void update(Company company) {
		getHibernateTemplate().update(company);
	}

	@Override
	public void delete(String id) {
		getHibernateTemplate().delete(get(id));
	}

	@Override
	public void delete(Company company) {
		getHibernateTemplate().delete(company);
	}

	@Override
	public List<Company> findByName(String name) {
		return (List<Company>)getHibernateTemplate().find("from Company c where c.name='"+name+"'");
	}

	@Override
	public List<Company> getAllCompanies() {
		// TODO Auto-generated method stub
		return (List<Company>)getHibernateTemplate().find("from Company");
	}

	@Override
	public List<Company> searchByName(String name) {
		// TODO Auto-generated method stub
		return (List<Company>)getHibernateTemplate().find("from Company c where c.name like '%"+name+"%'");
	}

}
